<?php
function encrypt($msg) {
  $td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
  $iv = config_item('initialization_vector');
  $key = mhash(MHASH_MD5,config_item('encryption_key'));
  /* Intialize encryption */
  mcrypt_generic_init($td, $key, $iv);

  /* Encrypt data */
  $encrypted_data = mcrypt_generic($td, $msg);

  /* Terminate encryption handler */
  mcrypt_generic_deinit($td);
  mcrypt_module_close($td);

  return $encrypted_data;
}

function decrypt($msg) {
  $td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
  $iv = config_item('initialization_vector');
  $key = mhash(MHASH_MD5,config_item('encryption_key'));
  /* Intialize encryption */
  mcrypt_generic_init($td, $key, $iv);

  /* Encrypt data */
  $encrypted_data = mdecrypt_generic($td, $msg);

  /* Terminate encryption handler */
  mcrypt_generic_deinit($td);
  mcrypt_module_close($td);

  return $encrypted_data;
}

?>